var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var ejs = require('ejs')
var error = require('./error')
var socket = require('./socket')
var login = require('./routes/login');
var order = require('./routes/order');
var logger = require('./logger');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('html', ejs.__express)
app.set('view engine', 'ejs');

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, '../AudioResource')));
app.use(express.static(path.join(__dirname, '../AudioSoundResource')));
app.use(express.static(path.join(__dirname, '../AudioMusicResource')));
app.use(login.get);
app.use(login.post);
app.use(order.get);
logger.useLogger(app);

app.use(error.create404);
app.use(error.errorHandler);
socket.init(app);

module.exports = app;
